import request from '@/utils/request'

/**
 * 账号密码登录
 * @param {Object} data   --账号密码对象
 * @returns  promise
 */
export const findUser = data => request({
  url: '/login',
  method: 'POST',
  data
})

/**
 * 获取手机号的短信验证
 * @param {String} mobile - 手机号
 * @returns promise
 */
export const userAccountLoginMsg = mobile => request({
  url: '/login/code',
  method: 'GET',
  params: {
    mobile
  }
})

/**
 * 手机验证码登录
 * @param {Object} data -手机号，验证码
 * @returns promise
 */
export const userMobileLogin = data => request({
  url: '/login/code',
  data,
  method: 'POST'
})

/**
 * QQ登录
 * @param {String} unionId -QQ唯一标识,openId
 * @param {*} source - 客户端类型 1 PC
 * @returns
 */

export const userQQlogin = (unionId, source = 1) => request({
  url: '/login/social',
  method: 'POST',
  data: {
    unionId,
    source
  }
})

/**
 * 获取QQ绑定的时候短信验证码
 * @param {*} mobile
 * @returns
 */
export const userQQBindCode = mobile => request({
  url: '/login/social/code',
  params: {
    mobile
  }
})

/**
  * QQ登录绑定账号
  * @param {String} unionId  - QQ唯一标识,openId
  * @param {String} mobile - 手机号
  * @param {String} code - 验证码
  * @returns
  */
export const userQQBindLogin = (unionId, mobile, code) => request({
  url: '/login/social/bind',
  method: 'POST',
  data: {
    unionId,
    mobile,
    code
  }
})

/**
 * 检测用户名唯一性
 * @param {String} account 用户名
 * @returns  promise
 */
export const userAccountCheck = account => request({
  url: '/register/check',
  params: {
    account
  }
})

/**
 * 获取QQ完善信息时候的短信验证码
 * @param {*} mobile -手机号
 * @returns
 */
export const userQQPatchCode = mobile => request({
  url: '/register/code',
  params: {
    mobile
  }
})
/**
 * 获取QQ完善信息时候的短信验证码
 * @param {String} unionId -QQ唯一标识
 * @param {Object} data  - form表单信息
 * @returns
 */
export const userPatch = (unionId, data) => request({
  url: `/login/social/${unionId}/complement`,
  data,
  method: 'POST'
})
